﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace CreaMotion.UserControls
{
	public partial class FieldItem : UserControl
	{
		public FieldItem()
		{
			this.InitializeComponent();
		}
        
        #region Source

        private Interfaces.Field source = null;
        public Interfaces.Field Source
        {
            get
            {
                return source;
            }
            set
            { 
                source = value;

                labFieldName.Text = value.FieldName;

                if (value.IsPrimaryKey)
                { 
                    ImagePk.Visibility = Visibility.Visible;
                    labFieldIcon.Visibility = Visibility.Hidden;
                }

                if(value.IsRelationship)
                {
                    switch (value.RelationshipType)
                    {
                        case CreaMotion.Interfaces.Field.RType.one:
                            labOneIcon.Visibility = Visibility.Visible;
                            labInfiniteIcon.Visibility = Visibility.Hidden;
                            break;
                        case CreaMotion.Interfaces.Field.RType.many:
                            labOneIcon.Visibility = Visibility.Hidden;
                            labInfiniteIcon.Visibility = Visibility.Visible;
                            break;
                    }

                    playEffect();
                }
            }
        }

        #endregion

        #region Play Effect

        void playEffect()
        {
            Storyboard tmp = this.FindResource("RelationshipEffect") as Storyboard ;
            BeginStoryboard(tmp);
        }

        #endregion
    }
}